home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # adv-attr.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
-
- # Still to be added:
- # parse the nsd.options file
-
- BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $query = new CGI;
-
- $nsswitch_cf = "/etc/nsswitch.conf";
- $dummy = "/etc/nsswitch.conf.tmp";
- $title = "Unified Name Service";
- $help_page = "adv-attr-help.html";
- $go = "adv-attr.cgi";
-
- $conf_map = $ARGV[0];
- $new = $query->param('new_map') if(! $conf_map);
-
- $js =
- "$js_standard
- $js_help
- $js_error_box
- function checkForm(form) {
- return (true);
- }";
-
-
- if($query->param('del') eq 'Yes') {
- &delete($conf_map);
- &redirect("adv-config.cgi?return");
- exit(0);
- }
-
- @lib_order =
- ($query->param('lib1'), $query->param('lib2'), $query->param('lib3'));
-
- if ($query->param('page2')) {
- &make_changes;
- &redirect("adv-config.cgi?return");
- exit(0);
- }
- @lib_order = &check_order(@lib_order);
-
- print $query->header;
- &read_attrs;
- &generic;
-
- sub check_order {
- local(@values) = @_;
- if ($values[0] eq "none") {
- $values[0] = $values[1];
- $values[1] = $values[2];
- $values[2] = "none";
- }
- if ($values[0] eq "none") {
- $values[0] = $values[1];
- $values[1] = "none";
- }
- return @values;
- }
-
- sub make_changes {
- &set_attrs;
-
- open(NSSWITCH, "$dummy");
- open(TEMP, ">$nsswitch_cf.new");
- if ($new) {
- while ($line = <NSSWITCH>) {
- print TEMP "$line";
- }
- &print_line($new);
- } else {
- while ($line = <NSSWITCH>) {
- if ($line =~ /^\s*[#\n]/) { print TEMP "$line"; next; }
- @entlist = split(/\s+/, $line);
- chop ($entlist[0]);
- $entlist[0] =~ s/(\S+)\s*(\(\S+\)*)$/\1/g;
-
- if ($conf_map eq $entlist[0]) {
- print TEMP "# $line";
- &print_line($conf_map);
- } else { print TEMP "$line"; }
- }
-
- }
- close(NSSWITCH);
- close(TEMP);
- rename("$nsswitch_cf.new", $dummy);
- }
-
- sub delete {
- local ($del_map) = @_[0];
- open(NSSWITCH, "$dummy");
- open(TEMP, ">$nsswitch_cf.new");
- while ($line = <NSSWITCH>) {
- if ($line =~ /^\s*[#\n]/) { print TEMP "$line"; next; }
- @entlist = split(/\s+/, $line);
- chop ($entlist[0]);
- $entlist[0] =~ s/(\S+)\s*(\(\S+\)*)$/\1/g;
-
- if ($del_map eq $entlist[0]) { print TEMP "# $line"; }
- else { print TEMP "$line"; }
- }
- close(NSSWITCH);
- close(TEMP);
- rename("$nsswitch_cf.new", $dummy);
- }
-
- sub generic {
- &js_title_block($title,$js);
- &header_block($title);
-
- print $query->startform("POST", "$go?$conf_map", "",
- "NAME=StandardForm", "onSubmit=\"return runSubmit()\"");
-
- print "<i>$message</i><p>\n";
- print "<input type=hidden name=page2 value=yes>\n";
- print "<input type=hidden name=new_map value=\"$new\">\n" if ($new);
- print "<input type=hidden name=lib1 value=\"$lib_order[0]\">\n";
- print "<input type=hidden name=lib2 value=\"$lib_order[1]\">\n";
- print "<input type=hidden name=lib3 value=\"$lib_order[2]\">\n";
- print "<center>
- You have chosen the following order of lookup services:<p>\n";
- if (! $conf_map) {
- print "$new";
- } else {
- print "$conf_map";
- }
- print ": $lib_order[0]";
- print " $lib_order[1]";
- print " $lib_order[2]";
- print "\n<p><hr width=\"50%\"></center><p>
- Now please enter any attributes each service should use
- for this map. If you do not enter a value, the default
- (shown in parentheses where available) will be used.<p>
- <center>\n";
- @numbers = ("1", "2", "3", "4");
- $i = 0;
- print "<table width=450>\n";
- &print_global($numbers[$i]);
- $i++;
- foreach $lib (@lib_order) {
- &print_files($numbers[$i]) if($lib eq 'files');
- &print_dns($numbers[$i]) if($lib eq 'dns');
- &print_nis($numbers[$i]) if($lib eq 'nis');
- &print_nisserv($numbers[$i]) if($lib eq 'nisserv');
- &print_mdbm($numbers[$i]) if($lib eq 'mdbm');
- &print_ndbm($numbers[$i]) if($lib eq 'ndbm');
- &print_db($numbers[$i]) if($lib eq 'db');
- &print_ldap($numbers[$i]) if($lib eq 'ldap');
- $i++;
- }
- print "</table></center>\n";
-
- print qq|<font size="+1"><center><table>\n|;
-
- print "</tr></table></center>";
- print "<p>\n";
-
- print &js_buttons('doit','Ok','onClick="markOK()"',
- 'onClick="markOther()"',
- "onClick=\"do_help('$help_page'); return (false)\"");
- print $query->endform;
- }
-
- sub print_line {
- &assemble_attrs(1);
- print TEMP "$_[0]$attr_string: ";
- for ($i = length("$$_[0]$attr_string: "); $i < 24; $i += 8) {
- print TEMP "\t";
- }
- # Assemble each library attributes
- for ($i = 0; $i < 3; $i++) {
- print TEMP "$lib_order[$i]" if ($lib_order[$i] ne "none");
- &assemble_attrs($i+2);
- print TEMP "$attr_string ";
- }
- # Done
- print TEMP "\n";
- }
-
- sub print_global {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. Map Attributes:</b>\n";
- print "<tr><td>timeout:<td><input name=global".$n."_timeout
- value=\"$map_attr{'timeout'}\"> (300 s)\n";
- print "<tr><td>mode:<td><input name=global".$n."_mode
- value=\"$map_attr{'mode'}\"> (0666)\n";
- print "<tr><td>local:<td><input name=global".$n."_local
- value=\"$map_attr{'local'}\"> (false)\n";
- print "<tr><td>null_extend_key:<td><input name=global".$n."_null_extend_key
- value=\"$map_attr{'null_extend_key'}\"> (false)\n";
- print "<p>\n";
- }
-
- sub print_files {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. Files Attributes:</b>\n";
- print "<tr><td>domain:<td><input name=file".$n."_domain
- value=\"$files_attr{'domain'}\"> \n";
- print "<tr><td>file:<td><input name=file".$n."_file
- value=\"$files_attr{'file'}\"> \n";
- print "<tr><td>compat:<td><input name=file".$n."_compat
- value=\"$files_attr{'compat'}\"> (false)\n";
- print "<tr><td>separator:<td><input name=file".$n."_separator
- value=\"$files_attr{'separator'}\"> (whitespace)\n";
- print "<p>\n";
- }
-
- sub print_dns {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. DNS Attributes:</b>\n";
- print "<tr><td>domain:<td><input name=dns".$n."_domain
- value=\"$dns_attr{'domain'}\"> \n";
- print "<tr><td>dns_servers:<td><input name=dns".$n."_dns_servers
- value=\"$dns_attr{'dns_servers'}\"> \n";
- print "<tr><td>dns_search:<td><input name=dns".$n."_dns_search
- value=\"$dns_attr{'dns_search'}\"> \n";
- print "<tr><td>dns_parallel:<td><input name=dns".$n."_dns_parallel
- value=\"$dns_attr{'dns_parallel'}\"> (false)\n";
- print "<tr><td>dns_retries:<td><input name=dns".$n."_dns_retries
- value=\"$dns_attr{'dns_retries'}\"> (3 queries)\n";
- print "<tr><td>dns_timeout:<td><input name=dns".$n."_dns_timeout
- value=\"$dns_attr{'dns_timeout'}\"> (1000 ms)\n";
- print "<p>\n";
- }
-
- sub print_nis {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. NIS Attributes:</b>\n";
- print "<tr><td>domain:<td><input name=nis".$n."_domain
- value=\"$nis_attr{'domain'}\"> \n";
- print "<tr><td>nis_multicast:<td><input name=nis".$n."_nis_multicast
- value=\"$nis_attr{'nsi_multicast'}\"> (32 hops)\n";
- print "<tr><td>nis_secure:<td><input name=nis".$n."_nis_secure
- value=\"$nis_attr{'nis_secure'}\"> (false)\n";
- print "<tr><td>nis_servers:<td><input name=nis".$n."_nis_servers
- value=\"$nis_attr{'nis_servers'}\"> \n";
- print "<tr><td>null_extend_key:<td><input name=nis".$n."_null_extend_key
- value=\"$nis_attr{'null_extend_key'}\"> (false)\n";
- print "<p>\n";
- }
-
- sub print_nisserv {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. NISSERV Attributes:</b>\n";
- print "<tr><td>domain:<td><input name=yp".$n."_domain
- value=\"$yp_attr{'domain'}\"> \n";
- print "<tr><td>nis_secure:<td><input name=yp".$n."_nis_secure
- value=\"$yp_attr{'nis_secure'}\"> (false)\n";
- print "<p>\n";
- }
-
- sub print_mdbm {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. MDBM Attributes:</b>\n";
- print "<tr><td>domain:<td><input name=mdbm".$n."_domain
- value=\"$mdbm_attr{'domain'}\"> \n";
- print "<tr><td>file:<td><input name=mdbm".$n."_file
- value=\"$mdbm_attr{'file'}\"> \n";
- print "<tr><td>null_extend_key:<td><input name=mdbm".$n."_null_extend_key
- value=\"$mdbm_attr{'null_extend_key'}\"> (false)\n";
- print "<p>\n";
- }
-
- sub print_ndbm {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. NDBM Attributes:</b>\n";
- print "<tr><td>domain:<td><input name=ndbm".$n."_domain
- value=\"$ndbm_attr{'domain'}\"> \n";
- print "<tr><td>file:<td><input name=ndbm".$n."_file
- value=\"$ndbm_attr{'file'}\"> \n";
- print "<tr><td>null_extend_key:<td><input name=ndbm".$n."_null_extend_key
- value=\"$ndbm_attr{'null_extend_key'}\"> (false)\n";
- print "<p>\n";
- }
-
- sub print_db {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. DB Attributes:</b>\n";
- print "<tr><td>domain:<td><input name=db".$n."_domain
- value=\"$db_attr{'domain'}\"> \n";
- print "<tr><td>file:<td><input name=db".$n."_file
- value=\"$db_attr{'file'}\"> \n";
- print "<tr><td>db_hash:<td><input name=db".$n."_db_hash
- value=\"$db_attr{'db_hash'}\"> (btree)\n";
- print "<tr><td>null_extend_key:<td><input name=db".$n."_null_extend_key
- value=\"$db_attr{'null_extend_key'}\"> (false)\n";
- print "<p>\n";
- }
-
- sub print_ldap {
- $n = $_[0];
- print "<tr><td colspan=2><b>$n. LDAP Attributes:</b>\n";
- print "<tr><td>error_timeout:<td><input name=ldap".$n."_error_timeout
- value=\"$ldap_attr{'error_timeout'}\"> (5 s)\n";
- print "<tr><td>open_timeout:<td><input name=ldap".$n."_open_timeout
- value=\"$ldap_attr{'open_timeout'}\"> (2 s)\n";
- print "<tr><td>search_timeout:<td><input name=ldap".$n."_search_timeout
- value=\"$ldap_attr{'search_timeout'}\"> (2 s)\n";
- print "<tr><td>max_requests:<td><input name=ldap".$n."_max_requests
- value=\"$ldap_attr{'max_requests'}\"> (3 queries)\n";
- print "<p>\n";
- }
-
- sub assemble_attrs {
- local ($num) = $_[0];
-
- if ($num == 1) { %vals = %final_map; }
- elsif ($num == 2) { %vals = %final_one; }
- elsif ($num == 3) { %vals = %final_two; }
- elsif ($num == 4) { %vals = %final_three; }
- foreach $key (keys %vals) {
- delete $vals{$key} if ($vals{$key} eq '!!!');
- }
-
- @keys = keys(%vals);
- $num_keys = $#keys;
- if ($num_keys >= 0) {
- $count = 0;
- $attr_string = "(";
- while ($count <= $num_keys) {
- $attr_string .= $keys[$count];
- if ($vals{$keys[$count]} ne "true") {
- if ($vals{$keys[$count]} =~ /\s/) {
- $attr_string .= "=\"$vals{$keys[$count]}\"";
- } else {
- $attr_string .= "=$vals{$keys[$count]}";
- }
- }
- $attr_string .= "," if ($count < $num_keys);
- $count++;
- }
- $attr_string .= ")";
- } else {
- $attr_string = "";
- }
- $attr_string =~ s/\'/\"/g;
- $attr_string =~ s/\"\"/\"/g;
- }
-
- sub read_attrs {
- undef @attr_list; $index = 1;
- while ($query->param("map_attr".$index)) {
- push(@attr_list, $query->param("map_attr".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $map_attr{$name} = $value;
- $map_attr{$name} = "true" if (!$value);
- }
-
- undef @attr_list; $index = 1;
- while ($query->param("files".$index)) {
- push(@attr_list, $query->param("files".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $files_attr{$name} = $value;
- $files_attr{$name} = "true" if (!$value);
- }
-
- undef @attr_list; $index = 1;
- while ($query->param("dns".$index)) {
- push(@attr_list, $query->param("dns".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $dns_attr{$name} = $value;
- $dns_attr{$name} = "true" if (!$value);
- }
-
- undef @attr_list; $index = 1;
- while ($query->param("nis".$index)) {
- push(@attr_list, $query->param("nis".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $nis_attr{$name} = $value;
- $nis_attr{$name} = "true" if (!$value);
- }
-
- undef @attr_list; $index = 1;
- while ($query->param("nisserv".$index)) {
- push(@attr_list, $query->param("nisserv".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $yp_attr{$name} = $value;
- $yp_attr{$name} = "true" if (!$value);
- }
-
- undef @attr_list; $index = 1;
- while ($query->param("mdbm".$index)) {
- push(@attr_list, $query->param("mdbm".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $mdbm_attr{$name} = $value;
- $mdbm_attr{$name} = "true" if (!$value);
- }
-
- undef @attr_list; $index = 1;
- while ($query->param("ndbm".$index)) {
- push(@attr_list, $query->param("ndbm".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $ndbm_attr{$name} = $value;
- $ndbm_attr{$name} = "true" if (!$value);
- }
-
- undef @attr_list; $index = 1;
- while ($query->param("db".$index)) {
- push(@attr_list, $query->param("db".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $db_attr{$name} = $value;
- $db_attr{$name} = "true" if (!$value);
- }
-
- undef @attr_list; $index = 1;
- while ($query->param("ldap".$index)) {
- push(@attr_list, $query->param("ldap".$index));
- $index++;
- }
- foreach $arg (@attr_list) {
- ($name, $value) = split("=", $arg);
- $ldap_attr{$name} = $value;
- $ldap_attr{$name} = "true" if (!$value);
- }
- }
-
- sub set_attrs {
- @names = $query->param;
- foreach $key (@names) {
- next if (($key eq 'doit') || ($key eq 'page2'));
- next if (($key =~ /^lib\d+$/));
-
- $name = $key;
- $number = $key;
-
- if (! $query->param($key)) { $attr_val = "!!!"; }
- else { $attr_val = $query->param($key); }
- $number =~ s/[^\d]//g;
- $name =~ s/^\w+\d_//g;
-
- if ($number == 1) { $final_map{$name} = $attr_val; }
- elsif ($number == 2) { $final_one{$name} = $attr_val; }
- elsif ($number == 3) { $final_two{$name} = $attr_val; }
- elsif ($number == 4) { $final_three{$name} = $attr_val; }
- }
- }
-